package com.dingqb.ktdemo.data

class Fanxing<T>(t: T) {
    var value = t;
}


fun <T : Any> getF(t: T) {
    var type = when (t) {
        is Int -> "Int--"
        is String -> "String--"
        else -> "other"
    }
    println("this data type ==$type")
    println(t.toString())
}

// 定义一个支持协变的类
class Runoob<out A>(val a: A) {
    fun foo(): A {
        return a
    }
}


// 定义一个支持逆变的类
class RunoobIn<in A>(a: A) {
    fun foo(a: A) {
    }
}

fun main(args: Array<String>) {

    var fanxing: Fanxing<String> = Fanxing("com.dingqb.ktdemo.base.Str");
    println(fanxing.value);

    var strCo: Runoob<String> = Runoob("a")
    var anyCo: Runoob<Any> = Runoob<Any>("b")
    anyCo = strCo
    println(anyCo.foo())   // 输出 a

    var strDCo = RunoobIn("a")
    var anyDCo = RunoobIn<Any>("b")
    strDCo = anyDCo
    println(strDCo === anyDCo);

    getF((1+2).toString());
}



